package com.googlecode.boliang.q13;

import java.util.HashMap;
import java.util.Map;

public class FirstCharAppearingOnlyOnce {

	public void getFirstChar(String inputStr) {
		
		char[] charArray = inputStr.toCharArray(); 
		Map<Character, Integer> charMap = new HashMap<Character, Integer>(); 
		
		
		for (int i = 0; i < charArray.length; i++) {
			if (charMap.containsKey(charArray[i])) {
				charMap.put(charArray[i], (charMap.get(charArray[i]) + 1)); 
			} else {
				charMap.put(charArray[i], 1); 
			}
		}
		
		for (int i = 0; i < charArray.length; i++) {
			if (charMap.get(charArray[i]) == 1) {
				System.out.println(charArray[i]); 
				return; 
			}
		}
		
		System.out.println("No character only appeared once!"); 
	}
}
